package pure.ui 
{
	import pure.ui.core.Component;
	import pure.ui.skins.IBackgroundSkin;
	import pure.ui.skins.ISkin;
	import pure.ui.skins.RetractileSkin;
	import flash.display.Bitmap;
	import flash.geom.Point;
	
	/**
	 * 图片
	 * @author Des
	 * <皮肤种类> ---- IBackgroundSkin
	 * 
	 */
	
public class Image extends Component 
{
	public function Image(x:Number, y:Number, size:Point, skin:ISkin=null, mouseEnabled:Boolean = false, mouseChildren:Boolean = false)
	{
		super(x, y, skin);
		setSize(size.x, size.y);
		this.mouseEnabled = mouseEnabled;
		this.mouseChildren = mouseChildren;
	}
	

	
	/*cache*/
	
	protected var _background:Bitmap;

	protected var _color:uint = 0xc3F3F3;
	
	protected var _thickness:Number = 2;

	protected var _lineColor:uint = 0;
	
	protected var _ellipse:Number = 8;
	
	protected var _alpha:Number = 0.9;
	
	
	
	
	/**
	 * 背景设定
	 * @param color			填充色
	 * @param thickness		边线粗细
	 * @param lineColor		边线颜色
	 * @param ellipse		四角内径
	 * @param alpha			透明度
	 **/
	public function setBackground(color:uint = 0xc3F3F3, thickness:Number = 2, lineColor:uint = 0, ellipse:Number = 8, alpha:Number = 0.9 ):void
	{
		_color = color;
		_thickness = thickness;
		_lineColor = lineColor;
		_ellipse = ellipse;
		_alpha = alpha;
		update();
	}
	
	/**
	 * 毁灭
	 */
	override public function destroy():void
	{
		super.destroy();
		removeChild(_background);
		if (_skin is RetractileSkin)
		{
			this._background.bitmapData.dispose();
		}
		_background = null;
		
	}
	
	
	
	
	/* ----------------------------------------------------    get / set    ----------------------------------------------------*/
	
	
	
	
		
	// 面板皮肤
	override public function set skin(value:ISkin):void
	{
		if (!value is IBackgroundSkin)
		{
			throw new Error('Image::skin - 皮肤类型错误！');
		}
		this._skin = value;
		update();
	}	
	
	
	
	
	
	/* ----------------------------------------------------    private    ----------------------------------------------------*/
	
	
	
	
	
	/**
	 * 子元素
	 */
	override protected function _addChildren():void
	{
		// 背景
		this._background = new Bitmap();
		addChild(this._background);
	}
	
	/**
	 * 绘制
	 **/
	override protected function _draw():void
	{
		if (this._skin)
		{
			if (_getBitmap("background"))
			{
				_skip("background");
				_clear();
			}
			else
			{
				if (this._background.bitmapData)
				{
					this._background.bitmapData = null;
				}
				_definition = null;
				_drawNoSkin(_color, _thickness, _ellipse,0.9 );
			}
		}
		else
		{
			_drawNoSkin(_color, _thickness, _ellipse );
		}
	}
	
	/**
	 * 更换位图
	 * @param definition		类定义名称
	 **/
	override protected function _skip(definition:String):void
	{
		this._background.bitmapData = _getBitmap(definition);
		this._definition = this._skin[definition];
	}
	

	
}

}